Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the runtime value of arguments to operations #5206

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

jtran
Copy link
Collaborator

@jtran jtran commented Jan 31, 2025

Resolves #5187.

Using the full values made the size of Operations a lot bigger. We only include UUIDs, bools, numbers, and strings. Geometry values like sketches only contain their artifact ID so that the UI can look it up in the artifact graph. TagDeclarator data isn't included because it doesn't seem to be needed, and the plan seems to be to remove them eventually.

Uses #5205.

Copy link

qa-wolf bot commented Jan 31, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Jan 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Feb 14, 2025 9:23pm

@franknoirot
Copy link
Collaborator

Are you concerned about the operations becoming a lot bigger?

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 91.42857% with 9 lines in your changes missing coverage. Please review.

Project coverage is 85.84%. Comparing base (834f713) to head (e10532e).

Files with missing lines Patch % Lines
src/wasm-lib/kcl/src/execution/cad_op.rs 88.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5206      +/-   ##
==========================================
+ Coverage   85.83%   85.84%   +0.01%     
==========================================
  Files          94       94              
  Lines       34758    34848      +90     
==========================================
+ Hits        29833    29914      +81     
- Misses       4925     4934       +9     
Flag Coverage Δ
wasm-lib 85.84% <91.42%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@franknoirot franknoirot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I'm excited to check it out more thoroughly on Monday, looks really promising

@franknoirot
Copy link
Collaborator

This is a good addition, I think the artifactId's will help a lot for getting these other edit flows to work. One issue I see is with shell, which admittedly is probably one of the trickiest cases.

With the following KCL:

sketch001 = startSketchOn('XZ')
  |> circle({ center = [0, 0], radius = 174.66 }, %)
extrude001 = extrude(100, sketch001)
shell001 = shell({ faces = ['end'], thickness = 40 }, extrude001)

I get the following JS object for the operations:

[
    {
        "type": "StdLibCall",
        "name": "startSketchOn",
        "unlabeledArg": null,
        "labeledArgs": {
            "data": {
                "value": {
                    "type": "String",
                    "value": "XZ",
                    "__meta": [
                        {
                            "sourceRange": [
                                26,
                                30,
                                0
                            ]
                        }
                    ]
                },
                "sourceRange": [
                    26,
                    30,
                    0
                ]
            }
        },
        "sourceRange": [
            12,
            31,
            0
        ]
    },
    {
        "type": "StdLibCall",
        "name": "extrude",
        "unlabeledArg": null,
        "labeledArgs": {
            "length": {
                "value": {
                    "type": "Number",
                    "value": 100,
                    "__meta": [
                        {
                            "sourceRange": [
                                106,
                                109,
                                0
                            ]
                        }
                    ]
                },
                "sourceRange": [
                    106,
                    109,
                    0
                ]
            },
            "sketch_set": {
                "artifactIds": [
                    "487cfafc-927a-423d-9e6b-63ed3ac2dba0"
                ],
                "sourceRange": [
                    111,
                    120,
                    0
                ]
            }
        },
        "sourceRange": [
            98,
            121,
            0
        ]
    },
    {
        "type": "StdLibCall",
        "name": "shell",
        "unlabeledArg": null,
        "labeledArgs": {
            "data": {
                "sourceRange": [
                    139,
                    174,
                    0
                ]
            },
            "solid_set": {
                "artifactIds": [
                    "dac9e1e6-0852-475e-9464-f25146fb423d"
                ],
                "sourceRange": [
                    176,
                    186,
                    0
                ]
            }
        },
        "sourceRange": [
            133,
            187,
            0
        ]
    }
]

I think I can get to the proper selection of the face artifact using the artifactId for the solid_set value plus the faces value pulled using the sourceRange for the data argument, but it is still pretty intense. This is another +1 for your proposal for flatter stdlib functions. But I'm wondering if the data function could have an artifactId field like the solid_set field has? Then based on context clues I could know (at least in this case) that any artifactIds on the data argument would be the face artifacts, which are what I want.

@jtran jtran force-pushed the jtran/sketch-artifact-id branch from 07201da to 2bd5f8d Compare February 4, 2025 18:01
@jtran jtran force-pushed the jtran/operation-runtime-value branch from 5639dc6 to e284472 Compare February 4, 2025 18:02
@jtran jtran force-pushed the jtran/sketch-artifact-id branch 3 times, most recently from 45053f1 to 18d5980 Compare February 6, 2025 01:01
@jtran jtran force-pushed the jtran/operation-runtime-value branch from e284472 to fbfaaa7 Compare February 6, 2025 01:02
@jtran
Copy link
Collaborator Author

jtran commented Feb 6, 2025

It seems like you want the full nested structure, which I was trying to avoid, but doing that should provide all the info you could ever want. I duplicated the entire structure of KclValue, replacing the parts that the UI doesn't need with only artifactId. I call it OpKclValue.

This is what a shell operation looks like.

  {
    "labeledArgs": {
      "faces": {
        "value": {
          "type": "Array",
          "value": [
            {
              "type": "String",
              "value": "end"
            }
          ]
        },
        "sourceRange": [
          97,
          104,
          0
        ]
      },
      "thickness": {
        "value": {
          "type": "Number",
          "value": 0.25
        },
        "sourceRange": [
          118,
          122,
          0
        ]
      }
    },
    "name": "shell",
    "sourceRange": [
      83,
      123,
      0
    ],
    "type": "StdLibCall",
    "unlabeledArg": {
      "value": {
        "type": "Solid",
        "value": {
          "artifactId": "[uuid]"
        }
      },
      "sourceRange": [
        0,
        0,
        0
      ]
    }
  }

@jtran
Copy link
Collaborator Author

jtran commented Feb 14, 2025

  1. Should the KCL expression arguments include their raw unparsed string value?

I guess I'm a little confused. We should have a huddle about this. Because it seems contradictory to want to use the expression, but also have the nested values. Example:

fn compute() {
  return {
    custom = {
      axis = [0, 0, 1],
      origin = [0, 0.25, 0],
    }
  }
}
x = compute()
helix(axis = x, ...)

For the axis argument, the expression is x. But the value is:

{
  custom = {
    axis = [0, 0, 1],
    origin = [0, 0.25, 0],
  }
}

I thought you wanted the value so that you could access deeply into the object, like origin. But if we do that, there's no meaningful expression at the call site. It's just a variable reference x. Does that make sense?

We already have the source range for the expression. So if you want to get the KCL of the expression x, you can do that. But it doesn't really make sense to have the KCL expression for origin because it's somewhere else, inside a function in this example.

  1. I don't understand the ty additional value appearing with KCL expressions, they don't seem to add any information about how to use the expression's value?

Units are part of numbers now in KCL. A lone numeric value is ambiguous without its units. The numeric type now includes what dimension and unit it is. I added it because it's available in the interpreter now, and it seems like we'd want the user to be able to see and/or edit it. I know that explicit units as in 5mm aren't used much in KCL today. But every day, support is growing. Just the other day, we had a discussion in Slack that cos(90deg) and cos(3.14rad) will do the right thing. That can only work if units are supported everywhere.

  1. Should we continue to include the artifactId for scene objects if we're planning on trying to filter those arguments from the edit flows? My thought is yes but just wanted to check

It seems useful because it allows us to tie it to the artifact graph. But if you don't think you need it, I'm happy to remove as much as possible from being exposed.

@franknoirot
Copy link
Collaborator

You're absolutely right @jtran, thanks for huddling with me.

  1. You are so right. I apologize, I lost context while doing other work, and forgot that we planned to use the source ranges to populate the command palette with KCL expression values.
  2. This is very exciting and makes sense. It's interesting that these defaults are passed along everywhere when the UoM is unknown, but I understand it far better now
  3. I think we should leave it in because rollback and editing of selection-based arguments is something I would like to continue work on immediately after we have confirmed our survival. It doesn't have impact on performance in the meantime

@jtran jtran force-pushed the jtran/operation-runtime-value branch from 437ce3d to e3e1005 Compare February 14, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return KclValue for operations' arguments, and artifactId or KclValue for operation itself
2 participants